using System;
using System.Collections.Generic;

namespace Infinity.Common.Logger
{
	/// <summary>
	/// MultiLogger factory class. User can use multi logger classes in the same time.
	/// </summary>
	public class MultiLogger : LoggerBase
	{
		private List<ILogger> _LoggerList;

		private MultiLogger()
		{
		}

		public static ILogger Create(params ILogger[] loggerList)
		{
			if (loggerList == null)
				throw new NullReferenceException("loggerList");

			var logger = new MultiLogger();
			logger._LoggerList = new List<ILogger>(loggerList);

			return logger;
		}

		public override void Flush()
		{
			_LoggerList.ForEach(x => x.Flush());
		}

		public override void Alert(string text)
		{
			_LoggerList.ForEach(x => x.Alert(text));
		}

		public override void Info(string text)
		{
			_LoggerList.ForEach(x => x.Info(text));
		}

		public override void Warning(string text)
		{
			_LoggerList.ForEach(x => x.Warning(text));
		}

		public override void Error(string text)
		{
			_LoggerList.ForEach(x => x.Error(text));
		}

		public override void Write(string text = "")
		{
			_LoggerList.ForEach(x => x.Write(text));
		}

		public override void WriteLine(string text = "")
		{
			_LoggerList.ForEach(x => x.WriteLine(text));
		}
	}
}